<template>
  <div class="common-head">
    <div class="head-fl">
      <i
        @click="toggleMenu"
        :class="$store.state.base.navCollapse?'el-icon-s-unfold': 'el-icon-s-fold'"></i>
      <!-- 面包屑导航 -->
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/dashBoard' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item v-if="$route.path !== '/dashBoard'">{{$route.name}}</el-breadcrumb-item>
      </el-breadcrumb>
      <!-- / 面包屑导航 -->
    </div>
    <div class="head-fr">
      <el-dropdown @command="clickDropdownMenu">
        <div class="user-info">
          <span>{{$store.state.user.userInfo.nickName}}</span>
          <el-avatar :size="40" :src="$store.state.user.userInfo.avatar"></el-avatar>
        </div>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="userInfo">个人中心</el-dropdown-item>
          <el-dropdown-item command="logout">退出登录</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </div>
</template>

<script>
export default {
  methods: {
    toggleMenu () {
      this.$store.commit('base/TOGGLE_MENU')
    },
    clickDropdownMenu (action) {
      // 点击用户下拉列表
      if (action === 'logout') {
        // 退出登录
        this.$store.commit('user/USER_LOGOUT')
        this.$router.go(0)
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.common-head{
  height: 100%;
  display: flex;
  justify-content: space-between;
  .head-fl{
    display: flex;
    align-items: center;
    i{
      margin-right: 10px;
      font-size: 20px;
      cursor: pointer;
    }
  }
  .head-fr{
    display: flex;
    align-items: center;
    cursor: pointer;
    .user-info{
      display: flex;
      align-items: center;
      height: 60px;
    }
    span{
      margin-right: 10px;
    }
  }
}
</style>
